// QueryEJB.java
package query;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;

import offer.Offer;

import descriptor.QueryDescriptor;

import student.Student;
import academicSup.AcademicSup;


/**
 * QueryBean
 * 
 * @author Mamadou TOURE
 * 
 * The QueryBean class implements all the methods that a remote client expect to find
 * when it calls the interface (Query).
 * 
 * Note : 	-It extends the EntityBean class.
 */
public  abstract class QueryBean implements EntityBean 
{
	// simple attributes
	/** 
	 * getId
	 * 
	 * The getId method returns a integer which indicates diary's identification number of a user.
	 * 
	 * @return		The diary's identification number of a user.
	 */
	public abstract int getId();
	
	/** 
	 * setId
	 * 
	 * The setId method sets the diary's identification number.
	 * 
	 * @param id		The new diary's identification number that we want to add.
	 */
	public abstract void setId(int id);
	
	/** 
	 * getMessage
	 * 
	 * The getMessage abstract method returns a string which contains the query's message.
	 * 
	 * @return		The query's message.
	 */
	public abstract String getMessage();
	
	/** 
	 * setMessage
	 * 
	 * The setMessage abstract method sets the message of the query.
	 * 
	 * @param msg		The new query's message.
	 */
	public abstract void setMessage(String msg);
	
	/** 
	 * getStatus
	 * 
	 * The getStatus abstract method returns a integer which indicates the status of the query.
	 * 
	 * @return		The query's message.
	 */
	public abstract int getStatus();
	
	/** 
	 * setStatus
	 * 
	 * The setStatus abstract method sets the status of the query.
	 * 
	 * @param status		The new query's status.
	 */
	public abstract void setStatus(int status);
	
	//bean attributes
	//relation 1-1
	/** 
	 * getStudent
	 * 
	 * The getStudent abstract method returns an object of type Student which provides the student's details,
	 * (eg. userID,......).
	 * 
	 * @return		A student's object.
	 */
	public abstract Student getStudent();
	
	/** 
	 * setStudent
	 * 
	 * The setStudent abstract method sets an object of type Student.
	 * 
	 * @param student		A new user's object..
	 */
	public abstract void setStudent(Student student);
	
	/** 
	 * getAcademicSup
	 * 
	 * The getAcademicSup abstract method returns an object of type AcademicSup which provides the academic Supervisor's details,
	 * (eg. userID,......).
	 * 
	 * @return		A AcademicSus's object.
	 */
	public abstract AcademicSup getAcademicSup();
	
	/** 
	 * setAcademicSup
	 * 
	 * The setAcademicSup abstract method sets an object of type AcademicSup.
	 * 
	 * @param student		A new AcademicSup's object.
	 */
	public abstract void setAcademicSup(AcademicSup academicSup);
	
	public abstract Offer getOffer();
	public abstract void setOffer(Offer offer);
	
	/** 
	 * ejbCreate
	 * 
	 * The ejbCreate method defines the operations to follow to create an EJB.
	 * This method refers to the method create in the remote interface.
	 * 
	 * @param msg				Query's message.
	 * @param student			Query's student owner.
	 * @param academicSup		Query's academic supervisor receiver.
	 * 
	 * @return 					Return's values is always null.
	 */
    public String ejbCreate(String msg, Student student, AcademicSup academicSup) throws CreateException
    {
    	setMessage(msg);
    	setStatus(Query.WAIT);
        return null;
    }
    
    /** 
	 * ejbPostCreate
	 * 
	 * The ejbPostCreate method defines the operations to follow after creating an EJB.
	 * 
	 * @param msg				Query's message.
	 * @param student			Query's student owner.
	 * @param academicSup		Query's academic supervisor receiver.
	 * 
	 */
    public void ejbPostCreate(String msg, Student student, AcademicSup academicSup) 
    {
    	setAcademicSup(academicSup);
    	setStudent(student);
    	setOffer(null);
    }
    
    /** 
	 * getDescriptor
	 * 
	 * The getDescriptor method provides a Java object instead of a bean object. Hence, the object is directly accessible from a servlet or a JSP. 
	 * 
	 * @param getId()					The ID of the query
	 * @param getMessage()				The query's message
	 * @param getStudent()				The query's student sender
	 * @param getAcademicSup()			The query's academic supervisor status
	 * @param getStatus()				The query's status (ie 0:Waiting for answer, -1:Rejected, 1:Accepted)
	 * 
	 * @return 							A Query Descriptor's object.
	 */
	public QueryDescriptor getDescriptor()
	{
		String offer = "";
		if(getOffer() != null)
		{
			offer = getOffer().getName();
		}
		return new QueryDescriptor(getId(),getMessage(),getStudent().getId(),getAcademicSup().getSurname() + " " +getAcademicSup().getFirstname(),offer,getStatus());
	}
    
    public void ejbActivate() throws EJBException, RemoteException {}
	public void ejbPassivate() throws EJBException, RemoteException {}
	public void ejbRemove() throws EJBException, RemoteException,RemoveException {}
	public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
	public void ejbLoad() throws EJBException, RemoteException {}
	public void ejbStore() throws EJBException, RemoteException {}
	public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
	public void unsetEntityContext() throws EJBException, RemoteException {}

}



